<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<meta http-equiv="Pragma" content="no-cache" />
		<meta http-equiv="Cache-Control" content="no-cache" />
		<meta http-equiv="Expires" content="0" />
		<meta http-equiv="X-UA-Compatible" content="E=edge;chrome=1" />
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<link rel="stylesheet" type="text/css" href="<%=path%>/static/css/reset.css">
		<link rel="stylesheet" type="text/css" href="<%=path%>/static/css/weui.min.css">
		<link rel="stylesheet" type="text/css" href="<%=path%>/static/css/index.css">
		<title>嘉华金融</title>
		
    </head>
    <body>
	<div>
		<div class="header">
			<div><div class="back"></div></div>
			<div>经销商信息</div>
			<div><!-- <div class="user-img"></div> --></div>
		</div>
		<div class="main">
			<div class="dealer-wrap">
				<div class="weui-cells">
		            <div class="weui-cell dealer-height">
		                <div class="weui-cell__hd"></div>
		                <div class="weui-cell__bd">
		                    <p>经销商等级</p>
		                </div>
		                <div class="weui-cell__ft">${roleName}</div>
		            </div>
		            <div class="weui-cell dealer-height">
		                <div class="weui-cell__hd"></div>
		                <div class="weui-cell__bd">
		                    <p>当月业务量</p>
		                </div>
		                <c:if test="${empty userBusiness}">
						  <div class="weui-cell__ft">0笔</div>
						</c:if>
						<c:if test="${not empty userBusiness}">
						  <div class="weui-cell__ft">${userBusiness.volume}笔</div>
						</c:if>
		            </div>
		            <div class="weui-cell">
		                <div class="weui-cell__hd"></div>
		                <div class="weui-cell__bd">
		                    <p>代理产品分润比例</p>
		                </div>
		            </div>
		           <c:choose>
					   <c:when test="${treamRole eq 'TOP'}">  
				        <c:forEach items="${shareLists}" var="item" varStatus="vs">
                           <div class="weui-cell delar-list">
                           <div class="weui-cell__hd home-icon" style="background:url('<%=path%>/file/getImg.html?saveAddress=${item.icon}');background-size:100% auto"></div>
                            <div class="weui-cell__bd home-p">
                                <p>${item.pname}</p>
                            </div>
                            <div class="weui-cell__ft">
                                <div>${item.value}</div>
                            </div>
                        </div>
                     </c:forEach>    
					 </c:when>
					   <c:otherwise>
					    <c:forEach items="${shareList}" var="item" varStatus="vs"> 
					     <div class="weui-cell delar-list">
					       <div class="weui-cell__hd home-icon" style="background:url('<%=path%>/file/getImg.html?saveAddress=${item.icon}');background-size:100% auto"></div>
                            <div class="weui-cell__bd home-p">
                                <p>${item.pname}</p>
                            </div>
                            <div class="weui-cell__ft">
                                <div>${item.value}</div>
                            </div>
                          </div>
                          </c:forEach>  
					   </c:otherwise>
					</c:choose>
		             <c:if test="${roleName ne '1 级经销商' && treamRole ne'LOW'}">
			             <div class="weui-cell">
			                <div class="weui-cell__hd"></div>
			                <div class="weui-cell__bd">
			                    <p>设置分销商利润比例</p>
			                </div>
			             </div>
			              <c:forEach items="${shareLists}" var="shareItem" varStatus="vs">
					        <div class="weui-cell dealer-height">
				                <div class="weui-cell__hd"></div>
				                <div class="weui-cell__bd">
				                    <p>${shareItem.pname}</p>
				                </div>
				                <div class="weui-cell__ft">
				                	<input class="weui-input input-right input_" value="${shareItem.onvalue}" defaultValue="${shareItem.value}" code="${shareItem.paltformId}">
				                </div>
				            </div>
			             </c:forEach>
			             <c:forEach items="${ownshareList}" var="shareItem" varStatus="vs">
                            <div class="weui-cell dealer-height">
                                <div class="weui-cell__hd"></div>
                                <div class="weui-cell__bd">
                                    <p>${shareItem.pname}</p>
                                </div>
                                <div class="weui-cell__ft">
                                    <input class="weui-input input-right input_" value="${shareItem.value}" defaultValue="1" code="${shareItem.platfromId}">
                                </div>
                            </div>
                         </c:forEach>
		             </c:if>
        		</div>
			</div>
		</div>
	</div>
</body>
<script type="text/javascript" src="<%=path%>/static/js/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="<%=path%>/static/layer/layer.js"></script>
<script type="text/javascript">
    var path="<%=path%>"
	$(".input_").change(function() {
		var $this = $(this);
		var value = $this.val();
		var platfromId = $this.attr("code");
		if(!validate(value)){
			layer.msg("请输入正确数字！", {time:1000});
			$this.val("");
			 return false ;  
		}
		var defaultValue = $this.attr("defaultValue");
		console.log(parseFloat(value))
		console.log(parseFloat(defaultValue))
		console.log(parseFloat(value)>parseFloat(defaultValue))
		if(parseFloat(value)>parseFloat(defaultValue)){
			layer.msg("对不起，下级代理分润不能大于上级分润！", {time:1000});
			$this.val("");
			//$this.attr("value",value);
			return false;  
		}else{
			 $.ajax({
                 url:path+"/editProfit.html",
                 data:{
                     value:value,
                     platfromId:platfromId
                  },
                 type : "POST",
                 datatype : "json",
                 async: false,
                 success : function(datas) {
                    flag=true;
                    var json =JSON.parse(datas);
                    layer.msg(json.msg, {time: 2000},function(){
                           flag=true;
                       });
                   }
              });			
		}
		
	});
	
	function validate(num){
	  var reg = /^\d+(?=\.{0,1}\d+$|$)/
	  if(reg.test(num)) return true;
	  return false ;  
	}
	
	$('.back').on('click', function () {
        window.location=path+"/member/memberCenter.html";
    });
</script>
</html>
